#include <iostream>
#include "serial.h"

int main(int argc, char *argv[])
{
    // 使用默认串口或命令行指定的串口
    std::string port = "/dev/ttyS6";
    if (argc > 1) {
        port = argv[1];
    }
    
    // 创建Serial对象
    Serial serial(port);
    
    // 打开串口
    if (!serial.open()) {
        std::cerr << "Failed to open serial port: " << port << std::endl;
        return 1;
    }
    
    std::cout << "Serial port " << port << " opened successfully" << std::endl;
    
    // 开0号板1号锁
    int boardId = 0;
    int lockId = 1;
    
    if (argc > 3) {
        boardId = atoi(argv[2]);
        lockId = atoi(argv[3]);
    }
    
    std::cout << "Attempting to open board " << boardId << " lock " << lockId << std::endl;
    
    // 调用开锁函数
    bool result = serial.queryLock(boardId, lockId);
    
    if (result) {
        std::cout << "Open lock command sent successfully" << std::endl;
    } else {
        std::cerr << "Failed to open lock" << std::endl;
    }
    
    // 串口会在Serial析构时自动关闭
    return 0;
}